import java.awt.geom.Arc2D.Double;
import java.util.*;

public class NBestList
{
    public class NBestResult implements java.lang.Comparable<NBestResult>
    {
        //public static NBestResult EMPTY = new NBestResult("", -1d, -1d, 0d);
        
        private String name;
        private double score;
        private double distance;
        private double angle;
        
        public NBestResult(String name, double score, double distance, double angle)
        {
            this.name = name;
            this.score = score;
            this.distance = distance;
            this.angle = angle;
        }
        
        public String name()
        {
            return this.name;
        }
        
        public double score()
        {
            return this.score;
        }
        
        public double distance()
        {
            return this.distance;
        }
        
        public double angle()
        {
            return this.angle;
        }
        
        public boolean isEmpty()
        {
            return this.score == -1.0;
        }

        public int compareTo(NBestResult o)
        {
            if (o instanceof NBestResult)
            {
                NBestResult r = (NBestResult) o;
                if (this.score < r.score)
                {
                    return 1;
                }
                else if (this.score > r.score)
                {
                    return -1;
                }
                else
                {
                    return 0;
                }
            }
            throw new java.lang.IllegalArgumentException("o is not a Result");
        }
    }
    
    private ArrayList<NBestResult> nBestList;
    
    public NBestList()
    {
        this.nBestList = new ArrayList<NBestResult>();
    }
    
    public boolean isEmpty()
    {
        return this.nBestList.isEmpty();
    }
    
    public void addResult(String name, double score, double distance, double angle)
    {
        this.nBestList.add(new NBestResult(name, score, distance, angle));
    }
    
    public void sortDescending()
    {
        Collections.sort(this.nBestList);
    }
    
    public String name()
    {
        if (!this.isEmpty())
        {
            return this.nBestList.get(0).name();
        }
        return "";
    }
    
    public double score()
    {
        if (!this.isEmpty())
        {
            return this.nBestList.get(0).score();
        }
        return -1.0;
    }
    
    public double distance()
    {
        if (!this.isEmpty())
        {
            return this.nBestList.get(0).distance();
        }
        return -1.0;
    }
    
    public double angle()
    {
        if (!this.isEmpty())
        {
            return this.nBestList.get(0).angle();
        }
        return 0.0;
    }
    
    public ArrayList<String> names()
    {
        ArrayList<String> result = new ArrayList<String>();
        if (!this.isEmpty())
        {
            for (NBestResult r : this.nBestList)
            {
                result.add(r.name());
            }
        }
        return result;
    }
    
    public String namesString()
    {
        String s = "";
        if (!this.isEmpty())
        {
            for (NBestResult r : this.nBestList)
            {
                s.concat(String.format("{0},", r.name()));
            }
            s = s.replaceAll("[" + "," + "]+$", "");
        }
        return s;
    }
    
    public ArrayList<java.lang.Double> scores()
    {
        ArrayList<java.lang.Double> result = new ArrayList<java.lang.Double>();
        if (!this.isEmpty())
        {
            for (NBestResult r : this.nBestList)
            {
                result.add(new java.lang.Double(r.score()));
            }
        }
        return result;
    }
    
    public String scoresString()
    {
        String s = "";
        if (!this.isEmpty())
        {
            for (NBestResult r : this.nBestList)
            {
                s.concat(String.format("{0:F3},", r.score()));
            }
            s = s.replaceAll("[" + "," + "]+$", "");
        }
        return s;
    }
}
